package py.ucom.sistemas.web.entradaspy.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ResourceBundle;

import py.ucom.sistemas.web.entradaspy.db.config.EntradasPyConfig;

public class Conexion {
	private String driver;
	private String user;
	private String pass;
	private String url;
	private EntradasPyConfig prop;
	private Connection conn;
	private ResourceBundle config;

	public Conexion(){
		prop = new EntradasPyConfig();
		config = EntradasPyConfig.fileConfig;
		loadMessages();
		try {
			Class.forName(driver);
			conn = DriverManager.getConnection(url,user,pass);
		} catch (SQLException e) {
			
			System.out.println(e.getLocalizedMessage());
		} catch (ClassNotFoundException e) {
			System.out.println(e.getMessage());
		}
	}
	
	public void loadMessages(){
		driver = config.getString("entradaspy.jdbc.driver");
		url = config.getString("entradaspy.jdbc.url");
		user = config.getString("entradaspy.jdbc.user");
		pass = config.getString("entradaspy.jdbc.pass");
	}
	
	public Connection getConnection(){
		return conn;
	}
	
	public void closeConnection(){
		try {
			conn.close();
		} catch (SQLException e) {
			System.out.println(e.getMessage());
		}
	}
	

}
